//
//  MHRecentMessageViewController.m
//  MiaoCircle
//
//  Created by 许正荣 on 2018/5/30.
//  Copyright © 2018年 acgera. All rights reserved.
//

#import "MHRecentMessageViewController.h"
#import "MHRecentMessageTableViewCell.h"
#import "MHRecentMessageViewModel.h"
#import "MHMessageNotification.h"
#import "MHChatViewModel.h"
#import "MHMomentViewModel.h"
@interface MHRecentMessageViewController ()
@property(nonatomic, strong) MHRecentMessageViewModel *viewModel;
@end

@implementation MHRecentMessageViewController
@dynamic viewModel;
- (void)viewDidLoad {
    [super viewDidLoad];
    [self.tableView mh_registerNibCell:MHRecentMessageTableViewCell.class];
    self.tableView.estimatedRowHeight = 120;
    self.tableView.rowHeight = UITableViewAutomaticDimension;
}


- (UITableViewCell *)tableView:(UITableView *)tableView dequeueReusableCellWithIdentifier:(NSString *)identifier forIndexPath:(NSIndexPath *)indexPath{
    
    return [tableView dequeueReusableCellWithIdentifier:@"MHRecentMessageTableViewCell"];
}

- (void)configureCell:(MHRecentMessageTableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath withObject:(id)object{
    [cell bindViewModel:object];
    cell.avterImageView.tag = indexPath.row;
    cell.avterImageView.userInteractionEnabled = YES;
    [cell.avterImageView bk_whenTapped:^{
        MHMessageNotification *model = self.viewModel.recentMessages[cell.avterImageView.tag];
        [[IMAPlatform sharedInstance] asyncGetStrangerInfo:[NSString stringWithFormat:@"%ld",(long)model.oprtUserId] succ:^(IMAUser *user) {
            IMAConversation *conversation =  [[IMAPlatform sharedInstance].conversationMgr chatWith:user];
            MHMomentViewModel *viewModel = [[MHMomentViewModel alloc] initWithServices:self.viewModel.services params:@{MHViewModelIsFootPrint:@(true),MHViewModelTitleKey:isEquaalCurrentUserId(user.userId)?@"我的足迹":@"Ta的足迹",MHViewModelConversation:conversation}];
            viewModel.userId = [user.userId intValue];
            viewModel.imUser = user;
            [self.viewModel.services pushViewModel:viewModel animated:YES];
        } fail:^(int code, NSString *msg) {
            
        }];
    }];
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
